<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>报价管理列表</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/new_general.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/MyDivWindow.css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery/DivWindow-1.0.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/My97DatePicker/WdatePicker.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/tools/validate.jsp"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/leftnav.js"></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/FreightDWR.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
</head>
<body>
<div id="layout">
	<jsp:include page="/index.do?method=head" flush="true"></jsp:include>
    <div id="mid">
    	<jsp:include page="/index.do?method=left" flush="true"></jsp:include>
    	<div id="mainpage">
    		<form action="" name="pageForm" method="post">
        	<div id="location">当前位置：<span class="fp"><a href="<%=request.getContextPath()%>/index.do?method=index">我的桌面</a></span>
        	<span><a>资料管理</a></span><span><a>报价管理</a></span></div>		    
            <div id="search">
            	<ul>
                	<li>报价编号：</li>
                    <li><input name="freight.code" id="freight.code" type="text" class="search_input" value="${form.freight.code}"/></li>
                </ul>
				<ul>
                    <li>录入日期：</li>
			        <li>
			        	<input name="startTime" type="text" id="startTime" class="search_input" readonly  value="${form.startTime}" onclick="WdatePicker()" />
			          	-
			        	<input name="endTime" type="text" id="endTime" class="search_input" readonly value="${form.endTime}" onclick="WdatePicker()" />
			        </li>
                </ul>
                <ul>
                	<li>
                    	<button onclick="renovate(1)" class="button_bg pic_bt">搜索</button>
                    </li>
                </ul>
            </div>
            <div class="index_pic">报价管理列表：</div> 
            <div id="inpageinfo"></div>
            <div id="operat_title_bottom"><button class="button_add" id="addShow" >新建</button></div>
		      <input type="hidden" name="orderByName" id="orderByName" value="${form.orderByName}"/>
		      <input type="hidden" name="orderByOrder" id="orderByOrder" value="${form.orderByOrder}"/>
            <div id="doc_content">
            <ul class="list_title">
            	<li class="manag_checkbox"></li>
            	<li class="price_doc_code" onClick="orderby(this)" id="code">报价编号</li>
                <li class="operate" onClick="orderby(this)" id="fromName">始发地</li>
                <li class="operate" onClick="orderby(this)" id="toName">目的地</li>             
                <li class="price_manag_uploaddept" onClick="orderby(this)" id="creatorName">录入人</li>
                <li class="price_uploaddate_time" onClick="orderby(this)" id="createDate">录入时间</li>
                <li class="price_operate">操作</li>
            </ul>
            <c:forEach var="freight" items="${form.list}"> 
            <ul class="doc_manag_list">
	          <li class="manag_checkbox">
	            <input name="ids" type="checkbox" value="${freight.id}"/>
	          </li>
	          <li class="price_doc_code"><span class="left">${freight.code}</span></li>
	          <li class="operate"><span class="center">${freight.fromName}</span></li>
	          <li class="operate"><span class="center">${freight.toName}</span></li>
			  <li class="price_manag_uploaddept"><span class="center">${freight.creatorName}</span></li>
			  <li class="price_uploaddate_time"><span class="center"><fmt:formatDate pattern="yyyy-MM-dd" type="both" dateStyle="default" timeStyle="default" value="${freight.createDate}" /></span></li>
			  <c:if test="${user.permissionMap.isUpdatePrice}">
			  	<li class="price_operate">
			  	<span class="center">
		            <a title="编辑" href="<%=request.getContextPath()%>/freight.do?method=load&freight.id=${freight.id}"><img src="<%=request.getContextPath()%>/images/edit_mini.png"/></a>         
		            <a class="d_box" title="删除" href="javascript:delOnly('${freight.id}');"><img src="<%=request.getContextPath()%>/images/delete.png"/></a>
	            </span>
	            </li>
	          </c:if>
	        </ul>
	        </c:forEach>
             </div>
            <div id="page"><%@ include file="/inc/pagecontrol.inc"%></div>
	          	<button id="chall" class="button_bg">全选</button>
	         	<button id="delAll" class="button_bg">删除</button>
			</form>
    	</div>
    </div>
<jsp:include page="/index.do?method=foot" flush="true"></jsp:include>
</div>
</body>
<script type="text/javascript">
//排序操作表单提交
function orderby(obj) {
	//状态更改以及排序设置
	var str = obj.innerHTML;
	if (obj.value == 1) {
		obj.value = 2;
		document.getElementById("orderByOrder").value = 2;
	} else {
		obj.value = 1;
		document.getElementById("orderByOrder").value = 1;
	}
	document.getElementById("orderByName").value = obj.id;
	document.forms['pageForm'].pageNo.value = 1;
	document.forms['pageForm'].submit();
}
orderByInit();
//初始化排序信息
function orderByInit() {
	var orderByName = document.getElementById("orderByName").value;
	var orderByOrder = document.getElementById("orderByOrder").value;
	if (orderByName.length < 1) {
		return;
	}
	var orderObj = document.getElementById(orderByName);
	orderObj.value = parseInt(orderByOrder);
	if (orderObj.value == 1) {
		orderObj.innerHTML = orderObj.innerHTML + "↓";
	} else if (orderObj.value == 2) {
		orderObj.innerHTML = orderObj.innerHTML + "↑";
	}
}
//全选事件
document.getElementById('chall').onclick=function(){
	var ids = document.getElementsByName('ids');
	if(this.name==""||this.name=="2")
		this.name="1";
	else
		this.name="2"
	for ( var i = 0; i < ids.length; i++) {
		ids[i].checked = (this.name=="1"?true:false);
	}
}
//搜索函数
function renovate(type){
	var chinpageinfo = document.getElementById("inpageinfo");
	if(type==0){
		document.forms['pageForm'].reset();
		}
	else{
		if(!document.getElementById("freight.code").value.isChar()&&document.getElementById("freight.code").value!=""){
			chinpageinfo.innerHTML="编号只能为字符或数字！";
			return;
		}
		var storageInStartTime = document.getElementById("startTime");
		var storageInEndTime = document.getElementById("endTime");
		if(!datecompare(storageInStartTime.value, storageInEndTime.value)){
			document.getElementById("inpageinfo").innerHTML="日期查询错误！须左侧日期小于右侧日期！";
			return;
			}
		document.forms['pageForm'].pageNo.value=1;
	}
	document.forms['pageForm'].submit();
}
//删除一条信息
function delOnly(objId){
	var chinpageinfo = document.getElementById("inpageinfo");
	var idsValue = [];
	idsValue[0] = objId;
	var take=function(data)
	{
		if(data){
			document.forms['pageForm'].submit();
		}
		else{
			chinpageinfo.innerHTML="当前项目不可删除！";
		}
	}
	var delale = new DivWindow("delale","系统提示",200,90,"确定要删除所选项目？");
	delale.addButton("确定",function(){
		FreightDWR.delAll(idsValue,take);
		closeDivWindow("delale");
		});	
	delale.addButton("取消");	
	delale.open();
}

//批量删除
if(document.getElementById('delAll')){
	document.getElementById('delAll').onclick=function(){
		var chinpageinfo = document.getElementById("inpageinfo");
		//DWR验证
		var ids = document.getElementsByName('ids');
		//将Values制作成数组
		var idsValue = [];
		var idsValuelength=0;
		for( var i = 0; i < ids.length; i++ )
		{
			if ( ids[i].checked ){
				idsValue[idsValuelength] = ids[i].value;
				idsValuelength++;
			}
		}
		if(idsValuelength==0){
			chinpageinfo.innerHTML="请选择要删除的项目！";
			return;
			}
		var take=function(data)
		{
			
			document.forms['pageForm'].submit();
				
		}
	
		var delale = new DivWindow("delale","系统提示",200,90,"确定要删除所选项目？");
		delale.addButton("确定",function(){
			FreightDWR.delAll(idsValue,take);
			closeDivWindow("delale");
			});	
		delale.addButton("取消");	
		delale.open();
	}
}
//添加页面
if(document.getElementById('addShow')){
	document.getElementById('addShow').onclick=function(){
		window.location = "<%=request.getContextPath()%>/freight.do?method=load";
	}
}

</script>
</html>
